package com.zr.daoImpl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.zr.dao.BanjiDaoHyx;
import com.zr.util.JDBCUtil;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

public class BanjiDaoImplHyx implements BanjiDaoHyx{

	@Override
	public JSONArray getAllBanji() {
		JSONArray js =new JSONArray();
		StringBuffer sql = new StringBuffer("");
		sql.append("SELECT banji.bid,banji.bname FROM banji");
		Connection con = JDBCUtil.getConnection();
		try {
			PreparedStatement pst = con.prepareStatement(sql.toString());
			ResultSet rs = pst.executeQuery();
			while(rs.next()){
				JSONObject j = new JSONObject();
				j.put("id", rs.getInt("bid"));
				j.put("text", rs.getString("bname"));
				js.add(j);
			}

			JDBCUtil.closeJDBC(pst, con);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return js;
	}
}
